package mlz.a_string;

//xxx.java -> 编译 -> xxx.class -> 运行 -> 内存

//特点: String对象的内容是不可变得,所以把String称之为不可变字符串对象
//字符串的常量池 -> 只要是直接使用""的变量都会存储在常量池中
public class StringDemo04 {
    public static void main(String[] args) {
        String name = "张三";
        name += "123";
        name += "456";
        System.out.println(name);//张三123456

        //常量池
        String s1 = "he";
        System.out.println();
        String s2 = "llo";
        String s3 = s1 + s2; //hello
        String s4 = "hello";
        String s5 = "he";
        //都是判断内存地址值是否相同

        System.out.println(s4 == s3);//false
        System.out.println(s4 == s1);//false
        System.out.println(s1 == s2);//false
        System.out.println(s1 == s5);//true
        //s1内存地址值
        int hashCode = System.identityHashCode(s1);
        String address = Integer.toHexString(hashCode);
        System.out.println(address);//6d311334

        //s4内存地址值
        int hashCode1 = System.identityHashCode(s4);
        String address1 = Integer.toHexString(hashCode1);
        System.out.println(address1);//682a0b20

        //s5内存地址值
        int hashCode2 = System.identityHashCode(s5);
        String address2 = Integer.toHexString(hashCode2);
        System.out.println(address2);//6d311334


    }
}
